package com.wbk.lotterysystemuserservice.service.serviceImpl;

import com.wbk.lotterysystemuserservice.entity.Store;
import com.wbk.lotterysystemuserservice.entity.StoreExample;
import com.wbk.lotterysystemuserservice.entity.User;
import com.wbk.lotterysystemuserservice.entity.UserExample;
import com.wbk.lotterysystemuserservice.mapper.StoreMapper;
import com.wbk.lotterysystemuserservice.mapper.UserMapper;
import com.wbk.lotterysystemuserservice.service.UserService;
import com.wbk.user.qo.UserBanQO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @Autowired
    UserMapper userMapper;

    @Override
    public List<User> getAllUser() {
        UserExample userExample=new UserExample();
        userExample.setOrderByClause("user_no asc");
        return userMapper.selectByExample(userExample);
    }

    @Override
    public String banUser(String username,UserBanQO userBanQO) {
        String key = "loginLock:" + username;
        stringRedisTemplate.opsForValue().set(key,userBanQO.getReason(),userBanQO.getExpire(), TimeUnit.HOURS);
        return "由于"+userBanQO.getReason()+","+username+"已被封禁"+userBanQO.getExpire()+"小时";
    }
}
